package cn.bdqn.mallmgr.controller.rec;

import cn.bdqn.mallmgr.pojo.User;
import cn.bdqn.mallmgr.service.UserService;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author
 * @create 2022-07-12 11:53
 */
@Controller
public class UserController {

    @Resource
    private UserService userService;

    //注册
    @PostMapping("/register")
    @ResponseBody
    public String register(@RequestBody User user) {
        HashMap<String, Object> result = new HashMap<>();
        Boolean flag = userService.register(user);
        if (flag) {
            result.put("code", 200);
            result.put("message", "注册成功");
        } else {
            result.put("code", 401);
            result.put("error", "注册失败");
        }
        return JSONArray.toJSONString(result);
    }
}
